<script setup lang='ts'>
  import { nextTick, reactive, ref } from 'vue';
  import { ToastWarning } from '@/utils/public';
  const formLabelWidth = '160px'
  const dataForm = ref()
  const $emit = defineEmits(['submit'])
  const action = reactive({
    dialogFormVisible:false,
    disabled:false,
    title:'',
    hourArr:[] as Array<any>,
  })
  interface formQuert {
    id:number
    admin_id:number
    type:number
    hour:number
  }
  let form = reactive({} as formQuert)
  const formRules = {
    type: [{ required: true, trigger: 'blur', message: '请选择处理类型' }],
    hour: [{ required: true, trigger: 'blur', message: '请选择封禁时间' }],
  }
  const handleSubmit = ()=>{
    $emit('submit','封禁成功',form)
    closeDialog()
  }
  const openDialog = (query:any = {})=> {
    const { id, hourArr=[], type=0, nickName } = query
    if(!type || !id) return ToastWarning('缺少关键参数')
    action.hourArr = hourArr
    Object.assign(form,{
      id,type
    })
    action.title = `${['','封禁','忽略','解封'][type]}用户：${nickName}`
    action.dialogFormVisible = true
  }
  const closeDialog = ()=>{
    form = reactive({} as formQuert)
    nextTick(() => {
      dataForm.value.clearValidate();
    });
    action.dialogFormVisible = false
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-dialog
    top="10vh"
    class="xm-dialog input-width"
    v-model="action.dialogFormVisible"
    :close-on-click-modal="action.disabled"
    :show-close="action.disabled"
    :close-on-press-escape="action.disabled"
    width="40%"
    :title="action.title">
      <el-form ref="dataForm" :model="form" :rules="formRules">
        <el-form-item :label-width="formLabelWidth" label="封禁时间" prop="hour">
          <el-select v-model="form.hour" placeholder="请选择封禁时间">
            <el-option v-for="item in action.hourArr" :label="item.text" :value="item.type" />
          </el-select>
        </el-form-item>
      </el-form>
      <template v-if="!action.disabled" #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="handleSubmit()">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>